package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbSellerMapper;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.pojo.TbSellerExample;
import com.dongdongshop.service.SellerService;
import com.dongdongshop.utils.ShiroUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@DubboService
public class SellerServiceImpl implements SellerService {

    @Resource
    private TbSellerMapper sellerMapper;

    //商家注册
    @Override
    public void register(TbSeller seller) {
        String salt = ShiroUtils.generateSalt(6); //生成盐
        seller.setMobile(salt);
        seller.setPassword(ShiroUtils.encryptPassword("MD5", seller.getPassword(), salt, 3)); //生成密文串
        seller.setStatus("0");
        sellerMapper.insertSelective(seller);
    }

    //查询全部商家
    @Override
    public List<TbSeller> getSellerList(String name, String nickName) {
        return sellerMapper.getSellerLikeName(name,nickName);
    }

    //获取商家信息审核
    @Override
    public TbSeller getSellerBySellerId(String sellerId) {
        TbSellerExample example = new TbSellerExample();
        TbSellerExample.Criteria criteria = example.createCriteria();
        criteria.andSellerIdEqualTo(sellerId);
        return sellerMapper.selectByExample(example).get(0);
    }

    //审核
    @Override
    public void updateAudit(String sellerId, String status) {
      sellerMapper.updateAudit(sellerId,status);
    }
}
